<template>
  <el-container class="rootbox">
    <el-main>
      <el-row :gutter="2">
        <el-col :span="24">
          <h3>所选科室:{{dept.name}}</h3>
          <h5>请先选择类型，然后选择类型标识。 序号、高度、高度不选系统默认分配。下级科室如果没有设置将继承上级科室的配置</h5>
        </el-col>
      </el-row>
      <data-view @extra-button-click="extraButtonClick" propViewKey="sys_workbench" @get-user-param="getUserParam"  @edit-input="editInput" ref="workbench"   propViewForm="sys/workbench/detail.vue"  @select-change="selectChange"    :propAutoFetchData="false" />
    </el-main>
  </el-container>
</template>

<script>
/* eslint-disable */

export default {
  name: 'workbench',
  data() {
    return {
      viewData: {},

      //每种类型数据加载标识，只加载一次
      ajaxLoadFlags: [false,false,false,false],

      //数据缓存
      ajaxLoadData: [null,null,null,null]
    }
  },
  methods: {
    //单元格改变
    async selectChange({row,column}) {
      let selectRow = column.selectRow
      if (column.property == 'flagType') { //类型选择后
        this.$set(row, 'typeKey', '')
        this.$set(row, 'title', '')
        this.$set(row, 'deptId', this.dept.id)
        this.$set(row, 'deptName', this.dept.name)
        this.$set(row, 'flagType', row[column.property])
      }else if (column.property == 'title') { //类型标识名称选择后 typeKey
        let typeKeyName='viewKey',titleNameKey='viewName'
        if (row.flagType == 'menu') {
          typeKeyName='route'
          titleNameKey='title'
        } else if (row.flagType == 'report' || row.flagType == 'chart') {
          typeKeyName='code'
          titleNameKey='name'
        }
        this.$set(row, 'typeKey', selectRow[typeKeyName])
        this.$set(row, 'title', selectRow[titleNameKey])
        if (!row.sortNum)  this.$set(row, 'sortNum', 99)
        if (!row.height)  this.$set(row, 'height', 300)
        if (!row.width)  this.$set(row, 'width', 12)
      }
    },

    getUserParam(param) {
      let wrapper = this.$newWrapper()
      let viewKey
      let msg ='未添加过的可用菜单'
      switch (param.row.flagType) {
        case "menu":
          viewKey = 'sys_menu_select'
          wrapper.notInSql('route', `select type_key from sys_workbench where flag_type='menu' and  dept_id =${this.dept.id}`)
          break
        case "report":
          msg ='未添加过的报表'
          viewKey = 'v_report_config_select'
          wrapper.eq('flagShowChart',0)
          wrapper.notInSql('code', `select type_key from sys_workbench where flag_type='report' and  dept_id =${this.dept.id}`)
          break
        case "chart":
          msg ='未添加过的图表'
          viewKey = 'v_report_config_select'
          wrapper.eq('flagShowChart',1)
          wrapper.notInSql('code', `select type_key from sys_workbench where flag_type='chart' and  dept_id =${this.dept.id}`)
          break
      }

      //固定数据筛选参数
      let userParam = {
        checkType: 'radio',
        useMsg: '数据筛选条件：'+msg,
        viewKey: viewKey,
        //筛选耗材的sql语句
      }

      param.call({userParam: userParam,editQueries: wrapper})
    },
    //行编辑普通input框的修改事件，比如修改耗材包的数量后自动更新基本单位的数量
    editInput({row, column}) {
      if (column.property == 'flagType') {
        this.$set(row, 'flagType', row.flagType)
        this.$refs.workbench.focusEditCell('title')
      }
    },
    extraButtonClick(para) {
      let buttonKey = para.button.key
      if (buttonKey == 'close') {
        // 审核通过
        this.$emit('close')
      }
    },
  },
  props: {
    dept: Object
  },
  watch: {
  }
}
</script>

<style lang="scss" scoped>
  .rootbox{
    .el-main{
      padding-top: 0 !important;
    }
  }

</style>
